<?php
//배열 원소마다 urlencode를 해주는 재귀함수 
function encode_items($array)
{
	foreach($array as $key => $value)
	{
		if(is_array($value))
		{
			$array[$key] = encode_items($value);
		}
		else
		{
			$array[$key] = urlencode($value);
		}
	}

	return $array;
}

function decode_items($array)
{
	foreach($array as $key => $value)
	{
		if(is_array($value))
		{
			$array[$key] = decode_items($value);
		}
		else
		{
			$array[$key] = urldecode($value);
		}
	}

	return $array;
}

function getParamToArray($str)
{	
	$str = str_replace("\"","",$str);
	$str = str_replace("\\","",$str);
	$array = explode('&', $str);
	$newArray = array();
	foreach($array as $val){
		$tmpArr = explode("=", $val);
		$tmpKey = $tmpArr[0];
		$tmpVal = $tmpArr[1];
		
		if(is_array($tmpVal)){
			$newArray[$tmpKey] = getParamToArray($tmpVal);
		}else{
			$newArray[$tmpKey] = $tmpVal;
		}
	}
	return $newArray;
}


function getPagingNumber($pageIndex){
	$startIndex = ($pageIndex * ROWCOUNT_PER_PAGE) - ROWCOUNT_PER_PAGE;
	$lastIndex = $pageIndex * ROWCOUNT_PER_PAGE;
	return array('startIndex'=>$startIndex, 'pageCount'=>ROWCOUNT_PER_PAGE);
}


function setLikePrefix($str){
	if(empty($str)){
		return '';
	}
	return '%'.$str.'%';
}

function logging($str){
	if(is_array($str)){
		$tStr = "PARAMETER == ";
		foreach($str as $k => $v){
			$tStr .= $k." => ".$v." ";
		}
		$str = $tStr; 
		//$str = 'array => '.implode($str,', ');
	}
	$logName = "log";
	$fileName = $_SERVER["DOCUMENT_ROOT"]."/log/".$logName;
	$logContent .= "[".date("Y-m-d H:i:s")."] ".$str."\n";

	$fp = fopen($fileName,'a');
	fwrite($fp,$logContent);
	if(is_readable($fileName)){
		chmod($fileName,0707);
	}
	fclose($fp);
}

?>